<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:awc="clr-namespace:Assergs.Windows.Controls"
    xmlns:aw="clr-namespace:Assergs.Windows"
	>
    
    <!-- New Brushes -->

	<LinearGradientBrush x:Key="MenuItemLeftBackgroundBrush" StartPoint="0,0.5" EndPoint="1,0.5">
		<GradientStop Color="{x:Static aw:DropDownMenuItemPallet.MenuItemLeftBackground1}" Offset="0"/>
		<GradientStop Color="{x:Static aw:DropDownMenuItemPallet.MenuItemLeftBackground2}" Offset="1"/>
	</LinearGradientBrush>
	
	<SolidColorBrush x:Key="NormalBorderBrush" Color="{x:Static aw:DropDownMenuItemPallet.NormalBorder}" />
	<SolidColorBrush x:Key="MenuItemsBackgroundBrush" Color="{x:Static aw:DropDownMenuItemPallet.MenuItemsBackground}" />
	<SolidColorBrush x:Key="ForegroundBrush" Color="{x:Static aw:DropDownMenuItemPallet.Foreground}" />
		
	<SolidColorBrush x:Key="MenuItemHighlightBorderBrush" Color="{x:Static aw:DropDownMenuItemPallet.LightBorder}"/>
	<SolidColorBrush x:Key="DisabledForegroundBrush" Color="{x:Static aw:DropDownMenuItemPallet.DisabledForeground}" />
	<SolidColorBrush x:Key="EditableControlBackgroundBrush" Color="{x:Static aw:DropDownMenuItemPallet.EditableControlBackground}" />
	<SolidColorBrush x:Key="GlyphBrush" Color="{x:Static aw:DropDownMenuItemPallet.Glyph}" />
	
	<LinearGradientBrush x:Key="MenuItemHighlightBackGroundBrush" StartPoint="0.5,0" EndPoint="0.5,1">
        <GradientStop Offset="0" Color="{x:Static aw:DropDownMenuItemPallet.MenuItemHighlightBackGround1}" />
        <GradientStop Offset="0.4" Color="{x:Static aw:DropDownMenuItemPallet.MenuItemHighlightBackGround2}" />
        <GradientStop Offset="0.4" Color="{x:Static aw:DropDownMenuItemPallet.MenuItemHighlightBackGround3}" />
        <GradientStop Offset="1" Color="{x:Static aw:DropDownMenuItemPallet.MenuItemHighlightBackGround4}" />
    </LinearGradientBrush>
    
    <!-- Separator -->
	<Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="Separator">
		<Setter Property="Height" Value="1"/>
		<Setter Property="Template"> 
			<Setter.Value>
				<ControlTemplate TargetType="Separator">
					<Border BorderBrush="{StaticResource NormalBorderBrush}" BorderThickness="1"/>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

	<!-- TopLevelHeader -->
	<ControlTemplate x:Key="TopLevelHeaderTemplateKey" TargetType="awc:DropDownMenuItem">
		<Border Name="Border" MinHeight="22">
			<Grid>
		
				<awc:DropDownHeaderButton 
					Name="PART_Button"
					IsToggleButtonChecked="{Binding Path=IsSubmenuOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
					Orientation="{TemplateBinding TopLevelButtonOrientation}"
					Text="{TemplateBinding HeaderText}"
					Content="{TemplateBinding Header}"
					DropDownButtonMode="{TemplateBinding DropDownButtonMode}"/>
				
				<Popup 
					Name="Popup"
					Placement="Bottom"
					IsOpen="{TemplateBinding IsSubmenuOpen}"
					AllowsTransparency="True" 
					Focusable="False"
					PopupAnimation="Fade">
					<Border 
						Name="SubmenuBorder"
						SnapsToDevicePixels="True"
						Background="Red"
						BorderBrush="{StaticResource NormalBorderBrush}"
						BorderThickness="1" >
					<StackPanel  
						Background="{StaticResource MenuItemsBackgroundBrush}"
						IsItemsHost="True" 
						KeyboardNavigation.DirectionalNavigation="Cycle" />
					</Border>
				</Popup>
			</Grid>
		</Border>
		
		<ControlTemplate.Triggers>
			<Trigger Property="IsSuspendingPopupAnimation" Value="true">
				<Setter TargetName="Popup" Property="PopupAnimation" Value="None"/>
			</Trigger>
			<Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True">
				<Setter TargetName="SubmenuBorder" Property="CornerRadius" Value="0,0,4,4"/>
				<Setter TargetName="SubmenuBorder" Property="Padding" Value="0,0,0,3"/>
			</Trigger>
			<Trigger Property="IsEnabled" Value="False">
				<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
			</Trigger>
		</ControlTemplate.Triggers>
	</ControlTemplate>
	
	
	<!-- TopLevelItem -->
	<ControlTemplate x:Key="TopLevelItemTemplateKey" TargetType="awc:DropDownMenuItem">
		<Border Name="Border" Background="Red">
			<Grid>
				<ContentPresenter 
					Margin="6,3,6,3" 
					ContentSource="Header"
					RecognizesAccessKey="True" />
			</Grid>
		</Border>
		<!--<ControlTemplate.Triggers>
			<Trigger Property="IsHighlighted" Value="true">
				<Setter TargetName="Border" Property="Background" Value="{x:Null}"/>
				<Setter TargetName="Border" Property="BorderBrush" Value="Transparent"/>
			</Trigger>
			<Trigger Property="IsEnabled" Value="False">
				<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
			</Trigger>
		</ControlTemplate.Triggers>-->
	</ControlTemplate>

	<!-- SubmenuItem -->

	<ControlTemplate x:Key="SubmenuItemTemplateKey" TargetType="awc:DropDownMenuItem">
		<Border Name="Border" MinHeight="24">
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" SharedSizeGroup="Icon"/>
					<ColumnDefinition Width="*" />
					<ColumnDefinition Width="Auto" SharedSizeGroup="Shortcut"/>
					<ColumnDefinition Width="13"/> 
				</Grid.ColumnDefinitions>
				
				<Border
					Name="LeftBackgroundBorder"
					BorderBrush="{StaticResource NormalBorderBrush}"
					Background="{StaticResource MenuItemLeftBackgroundBrush}"
					Width="28"
					BorderThickness="0,0,1,0"/>
					
				<Border
                    Name="HighlightedBorder"
                    CornerRadius="2"
                    Margin="2,1,2,1"
                    Grid.ColumnSpan="4"
                    BorderThickness="1"/>
				
				<ContentPresenter 
					Name="Icon"
					Margin="6,0,6,0"
					VerticalAlignment="Center"
					ContentSource="Icon"/>
					
				<Border 
					Name="Check"  
					Width="13" Height="13" 
					Visibility="Collapsed"
					Margin="6,0,6,0" 
					BorderThickness="1"
					BorderBrush="{StaticResource NormalBorderBrush}">
					<Path 
						Name="CheckMark"
						Width="7" Height="7" 
						Visibility="Hidden" 
						SnapsToDevicePixels="False" 
						Stroke="{StaticResource GlyphBrush}"
						StrokeThickness="2"
						VerticalAlignment="Center"
						Data="M 0 0 L 7 7 M 0 7 L 7 0" />
				</Border>
				
				<ContentPresenter 
					Name="HeaderHost"
					Grid.Column="1"
					ContentSource="Header"
					VerticalAlignment="Center"
					RecognizesAccessKey="True"
					Margin="6,0,0,0"/>
					
				<TextBlock x:Name="InputGestureText"
					Grid.Column="2"
					Text="{TemplateBinding InputGestureText}"
					Margin="5,2,0,2"
					VerticalAlignment="Center"
					DockPanel.Dock="Right" />
			</Grid>
		</Border>
		
		<ControlTemplate.Triggers>
			<Trigger Property="Icon" Value="{x:Null}">
				<Setter TargetName="Icon" Property="Visibility" Value="Hidden"/>
			</Trigger>
			<Trigger Property="IsChecked" Value="true">
				<Setter TargetName="CheckMark" Property="Visibility" Value="Visible"/>
			</Trigger>
			<Trigger Property="IsCheckable" Value="true">
				<Setter TargetName="Check" Property="Visibility" Value="Visible"/>
				<Setter TargetName="Icon" Property="Visibility" Value="Hidden"/>
			</Trigger>
			<MultiTrigger>
				<MultiTrigger.Conditions>
					<Condition Property="IsHighlighted" Value="true" />
					<Condition Property="IsPanelContainer" Value="False" />
				</MultiTrigger.Conditions>
				<Setter TargetName="HighlightedBorder" Property="Background" Value="{StaticResource MenuItemHighlightBackGroundBrush}"/>
				<Setter TargetName="HighlightedBorder" Property="BorderBrush" Value="{StaticResource MenuItemHighlightBorderBrush}"/>
			</MultiTrigger>
			<Trigger Property="IsPanelContainer" Value="True">
				<Setter TargetName="LeftBackgroundBorder" Property="Visibility" Value="Collapsed"/>				
				<Setter TargetName="HighlightedBorder" Property="Visibility" Value="Collapsed"/>				
				<Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>				
				<Setter TargetName="Check" Property="Visibility" Value="Collapsed"/>				
				<Setter TargetName="InputGestureText" Property="Visibility" Value="Collapsed"/>				
				<Setter TargetName="HeaderHost" Property="Grid.Column" Value="0"/>				
				<Setter TargetName="HeaderHost" Property="Grid.ColumnSpan" Value="4"/>
				<Setter TargetName="HeaderHost" Property="Margin" Value="1,0,1,0"/>
				<Setter TargetName="Border" Property="BorderThickness" Value="0,1,0,1"/>
				<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource NormalBorderBrush}"/>
			</Trigger>
			<Trigger Property="IsEnabled" Value="false">
				<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
			</Trigger>
		</ControlTemplate.Triggers>
		
	</ControlTemplate>

	<!-- SubmenuHeader -->

	<ControlTemplate x:Key="SubmenuHeaderTemplateKey" TargetType="awc:DropDownMenuItem">
		<Border Name="Border" MinHeight="24">
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" SharedSizeGroup="Icon"/>
					<ColumnDefinition Width="*" />
					<ColumnDefinition Width="Auto" SharedSizeGroup="Shortcut"/>
					<ColumnDefinition Width="13"/>
				</Grid.ColumnDefinitions>
				
				<Border
					Name="LeftBackgroundBorder"
					BorderBrush="{StaticResource NormalBorderBrush}"
					Background="{StaticResource MenuItemLeftBackgroundBrush}"
					Width="28"
					BorderThickness="0,0,1,0"/>
					
				<Border
                    Name="HighlightedBorder"
                    CornerRadius="2"
                    Margin="2,1,2,1"
                    Grid.ColumnSpan="4"
                    BorderThickness="1"/>
				
				<ContentPresenter 
					Name="Icon"
					Margin="6,0,6,0"
					VerticalAlignment="Center"
					ContentSource="Icon"/>
					
				<ContentPresenter 
					Name="HeaderHost"
					Grid.Column="1"
					ContentSource="Header"
					VerticalAlignment="Center"
					RecognizesAccessKey="True"
					Margin="6,0,0,0"/>
					
				<TextBlock x:Name="InputGestureText"
					Grid.Column="2"
					Text="{TemplateBinding InputGestureText}"
					Margin="5,2,2,2"
					VerticalAlignment="Center"
					DockPanel.Dock="Right"/>
					
				<Path 
					Grid.Column="3"
					HorizontalAlignment="Center"
					VerticalAlignment="Center"
					Data="M 0 0 L 0 7 L 4 3.5 Z" 
					Fill="{StaticResource GlyphBrush}" />
					
				<Popup 
					Name="Popup"
					Placement="Right"
					HorizontalOffset="-4" 
					IsOpen="{TemplateBinding IsSubmenuOpen}"
					AllowsTransparency="True" 
					Focusable="False"
					PopupAnimation="Fade">
					<Border 
						Name="SubmenuBorder"
						SnapsToDevicePixels="True"
						Background="{StaticResource EditableControlBackgroundBrush}"
						BorderBrush="{StaticResource NormalBorderBrush}"
						BorderThickness="1" >
						<StackPanel  
							Background="{StaticResource MenuItemsBackgroundBrush}"
							IsItemsHost="True" 
							KeyboardNavigation.DirectionalNavigation="Cycle" />
					</Border>
				</Popup>
			</Grid>
		</Border>
		
		<ControlTemplate.Triggers>
			<Trigger Property="Icon" Value="{x:Null}">
				<Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
			</Trigger>
			<Trigger Property="IsHighlighted" Value="true">
				<Setter TargetName="HighlightedBorder" Property="Background" Value="{StaticResource MenuItemHighlightBackGroundBrush}"/>
				<Setter TargetName="HighlightedBorder" Property="BorderBrush" Value="{StaticResource MenuItemHighlightBorderBrush}"/>
			</Trigger>
			<Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True">
				<Setter TargetName="SubmenuBorder" Property="CornerRadius" Value="4"/>
				<Setter TargetName="SubmenuBorder" Property="Padding" Value="0,3,0,3"/>
			</Trigger>
			<Trigger Property="IsEnabled" Value="false">
				<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
			</Trigger>
		</ControlTemplate.Triggers>
	</ControlTemplate>

<!-- MenuItem Style -->
<Style x:Key="{x:Type awc:DropDownMenuItem}" TargetType="awc:DropDownMenuItem">
  <Setter Property="OverridesDefaultStyle" Value="True"/>
  <Setter Property="SnapsToDevicePixels" Value="True"/>
  <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
  <Style.Triggers>
    <Trigger Property="Role" Value="TopLevelHeader">
      <Setter Property="Template" Value="{StaticResource TopLevelHeaderTemplateKey}"/>
      <Setter Property="Grid.IsSharedSizeScope" Value="true"/>
    </Trigger>
    <Trigger Property="Role" Value="TopLevelItem">
      <Setter Property="Template" Value="{StaticResource TopLevelItemTemplateKey}"/>
    </Trigger>
    <Trigger Property="Role" Value="SubmenuHeader">
      <Setter Property="Template" Value="{StaticResource SubmenuHeaderTemplateKey}"/>
    </Trigger>
    <Trigger Property="Role" Value="SubmenuItem">
      <Setter Property="Template" Value="{StaticResource SubmenuItemTemplateKey}"/>
    </Trigger>
  </Style.Triggers>
</Style>

</ResourceDictionary>